package my.algorithms;

public class Fibonacci
{
    public static void linearFib1(int n)
    {
        int previous = 1;
        int current = 1;
        
        //if (n == 1 || n == 2)
            System.out.print("1 1 ");
        
        for (int i = 2; i < n; i++)
        {
            int temp = current;
            current = current + previous;
            previous = temp;
            System.out.print(current + " ");
            
        }
        
    }
    
    public static void linearFib2(int n)
    {
        int previous = 1;
        int current = 1;
        for (int i = 0 ; i < n; i++)
        {
            if (i < 2)
            {
                System.out.print("1 ");
            }
            else
            {
                int tmp = current;
                current = current + previous;
                previous = tmp;
                System.out.print(current + " ");
                
            }
        }
        
    }
    
    public static int recursiveFib(int n)
    {
        if (n == 1 || n == 2)
        {
            return 1;
        }
        else
        {
            return recursiveFib(n - 1) + recursiveFib(n - 2);
        }
    }
}
